import company from '../views/database/company.json'
import busNum from '../views/database/busNum.json'
import user from '../views/database/user.json'

export function getLocalData(type) {
  return JSON.parse(localStorage.getItem(type))
}

export function getLocalDataAll() {
  let company = localStorage.getItem('company'),
      busNum = localStorage.getItem('busNum'),
      user = localStorage.getItem('user')
  company = JSON.parse(company),
      busNum = JSON.parse(busNum),
      user = JSON.parse(user)
  return {company, busNum, user}
}

export function setLocalData(type, data) {
  localStorage.setItem(type, JSON.stringify(data))
}

export function initLocaLData() {
  let companyLocal = localStorage.getItem('localStore')
  if (companyLocal) return
  localStorage.setItem("localStore", "true")
  localStorage.setItem("company", JSON.stringify(company))
  localStorage.setItem("busNum", JSON.stringify(busNum))
  localStorage.setItem("user", JSON.stringify(user))
}
